#include "rkmedia_function_register.h"

videoQueue *high_video_queue = NULL;
rkmediaInfo *rkmedia_config = NULL;
containerInfo *above_container_func = NULL;

int main(int argc, char *argv[])
{
    
    if (argc != 3)
    {
        cout << "Usage:exe stream_type url_address Notice URL_TYPE: 0-->FLV  1-->TS" << endl;
        cout << "Eg:./import_face_data_db_main 0 rtmp://192.168.1.88:1935/live/high" << endl;
        return -1;
    }
 
    if (IQ_FILE_PATH)
    {
#ifdef RKAIQ
        rk_aiq_working_mode_t hdr_mode = RK_AIQ_WORKING_MODE_NORMAL;
        RK_BOOL bMultictx = RK_FALSE;
        SAMPLE_COMM_ISP_Init(CAMERA_ID, hdr_mode, bMultictx, IQ_FILE_PATH);
        SAMPLE_COMM_ISP_Run(CAMERA_ID);
        SAMPLE_COMM_ISP_SetFrameRate(CAMERA_ID, RK_FPS);
        
        printf("#Rkaiq XML DirPath: %s\n", IQ_FILE_PATH);
        printf("#bMultictx: %d\n\n", bMultictx);
#endif
    }

    int ret = -1;
    high_video_queue = new videoQueue();
    rkmedia_config = new rkmediaInfo();
    above_container_func = new containerInfo();

    if (rkmedia_config->rkmedia_module_init())
    {
        printf("rkmedia module init failed...\n");
        return -1;
    }
    else
    {
        printf("rkmedia module init success...\n");
    }

    if (rkmedia_function_achieve(atoi(argv[1]), argv[2]))
    {
        printf("rkmedia module achieve failed...\n");
        return -1;
    }
    else
    {
        printf("rkmedia module achieve success...\n");
    }
    while (1)
    {
        usleep(500000);
    }

    MPP_CHN_S stViChn;
    MPP_CHN_S stRgaChn;

    RV1126_VI_CONTAINER vi_container;
    above_container_func->get_vi_container(0, &vi_container);
    stViChn.enModId = RK_ID_VI;
    stViChn.s32ChnId = vi_container.vi_chn;
    //stViChn.s32DevId = CAMERA_ID;

    RV1126_RGA_CONTAINER rga_container;
    above_container_func->get_rga_container(0, &rga_container);
    stRgaChn.enModId = RK_ID_RGA;
    stRgaChn.s32ChnId = rga_container.rga_chn;
    ret = RK_MPI_SYS_UnBind(&stViChn, &stRgaChn);
    if (ret)
    {
        printf("UnBind rga chn failed...\n");
        return -1;
    }
    else
    {
        printf("UnBind rga chn success...\n");
    }

    RV1126_VENC_CONTAINER venc_container;
    above_container_func->get_venc_container(0, &venc_container);

    RK_MPI_VENC_DestroyChn(venc_container.venc_chn);
    RK_MPI_RGA_DestroyChn(rga_container.rga_chn);
    RK_MPI_VI_DisableChn(CAMERA_ID, vi_container.vi_chn);
    delete high_video_queue;
    delete rkmedia_config;
    delete above_container_func;

    if (IQ_FILE_PATH)
    {
#ifdef RKAIQ
        SAMPLE_COMM_ISP_Stop(CAMERA_ID);
#endif
    }
    
    return 0;
}
